package edu.fim.core.service.locator;

import java.util.ServiceLoader;

import edu.fim.core.exception.ImplementationNotFoundException;


public class ServiceLocator {

	public static <T> T getImplementation(Class<T> interFace) throws ImplementationNotFoundException {
		ServiceLoader<T> implementations = ServiceLoader.load(interFace);
		for (T clazz : implementations) {
			if (clazz != null) {
				return clazz;
			}
		}
		throw new ImplementationNotFoundException("Cannot find implementation for " + interFace.getName());
	}
}